#!/usr/bin/python3
# coding=utf-8

import os
import yaml
import openpyxl
import pandas as pd

# 针对不同文件内容的读取方式进行简单封装


class YAMLReader(object):
    def __init__(self, target_file):
        """Read YAML File
        :param target_file: read YAML file
        :type target_file: string
        """
        if os.path.exists(target_file):
            self.yaml_obj = target_file

        else:
            raise FileNotFoundError(f"File <{target_file}> not found!")

        self._data = None

    @property
    def data(self):
        """read yaml file and convert to List
        :return data: read from yaml file
        :rtype data: list
        """
        if not self._data:
            with open(self.yaml_obj, "rb") as f:
                self._data = list(yaml.safe_load_all(f))

        return self._data


def get_TestCases_by_ExcelFile(excel_file):
    if excel_file:
        df = pd.read_excel(excel_file)
        # 获取列名
        column_names = df.columns.values
        print(column_names)

        # # 获取行，列数(默认去掉了第一行列名)
        # row_count, column_count = df.shape
        # print(row_count +1, column_count +1)
        # # 第二种方法
        # row_count, column_count = len(df) +1 , len(df.columns) +1
        # print(row_count +1, column_count +1)

        # 遍历(忽略title)
        for item in df.values:
            print(item)

        return df.values


if __name__ == "__main__":
    # src = 'D:/MyProjects/General_API_Draft/configs/setting.yaml'
    # demo = YAMLReader(src)
    excel_file = "D:/MyProjects/General_API_Draft/testdata/api_testcase_template.xlsx"
    get_TestCases_by_ExcelFile(excel_file)
